package org.kjtc.balanceController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.kjtc.balanceEntity.StationStandard;
import org.kjtc.balanceService.StationStandardService;
import org.kjtc.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class StationStandardController extends BaseController{

	@Resource(name = "stationStandardService")
	private StationStandardService stationStandardService;
	
	@RequestMapping(value = "/searchStationStandard")
	@ResponseBody
	public Map<String, Object> searchStationStandard(){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "场站标准查询");

		List<StationStandard> list = null;
		try {
			list = stationStandardService.getStationStandard();
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "场站标准查询异常" + e.getMessage());
			return map;
		}
		map.put("stationStandardList", list);
		return map;
	}
	
	@ResponseBody
	@RequestMapping(value = "/saveStationStandard")
	public Map<String, Object> saveStationStandard(StationStandard stationStandard){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "场站标准添加");
		int count = 0;
		try {
			count = stationStandardService.insertStationStandard(stationStandard);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		}  catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "场站标准添加异常");
		}
		stationStandard = null;
		return map;
	}
	
	@RequestMapping(value = "/updateStationStandard")
	@ResponseBody
	public Map<String, Object> updateStationStandard(StationStandard stationStandard) {

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "场站标准修改");
		int count = 0;
		try {
			count = stationStandardService.updateStationStandard(stationStandard);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "场站标准修改异常");
		}
		stationStandard = null;
		return map;
	}
	
	@RequestMapping(value = "/deleteStationStandard")
	@ResponseBody
	public Object deleteStationStandard(String ID) {

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "场站标准删除");
		StationStandard stationStandard = new StationStandard();
		int count = 0;
		try {
			stationStandard.setID(Integer.parseInt(ID));
			count = stationStandardService.deleteStationStandard(stationStandard);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "场站标准删除异常:" + e.getMessage());
		}
		stationStandard = null;
		return map;
	}
}
